package com.lwc.common.bean;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class MapUtils {
  public  static   Map convertToMap(Class clazz,Object object) {
        Map map = new HashMap();
        //利用反射获取当前类的所有字段
        Field[] fields = clazz.getDeclaredFields();
        //遍历
        for (Field f : fields) {
            //设置字段访问 设置为true 私有的也可以访问
            f.setAccessible(true);
            //获取字段名称
            String key = f.getName();
            //获取该字段的值
            Object value = null;
            try {
                value = f.get(object);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            map.put(key, value);
        }
        return map;
    }


    public  static Integer getIntValues(Map map,String key){
if (null==map|| !map.containsKey(key)){
    return null;
}
//取值
        Object obj=map.get(key);
if (null==obj){
return  null;
}
return  Integer.parseInt(obj.toString());
    }
    public  static String getStringValues1(Map map,String key){
        if (null==map|| !map.containsKey(key)){
            return null;
        }
//取值
        Object obj=map.get(key);
        if (null==obj){
            return  null;
        }
        return obj.toString();
    }


}



